export const setTMToken = (token: string) =>
  localStorage.setItem("IM_TOKEN", token);
export const setChatToken = (token: string) =>
  localStorage.setItem("IM_CHAT_TOKEN", token);
export const setTMUserID = (userID: string) =>
  localStorage.setItem("IM_USERID", userID);
export const setChatType = (chatType: string) =>
  localStorage.setItem("IM_ChatType", chatType);
export const setAdminToken = (adminToken: string) =>
  localStorage.setItem("IM_ADMIN_TOKEN", adminToken);
export const setAccessedFriendApplication = (list: string[]) =>
  localStorage.setItem(
    `${getIMUserID()}_accessedFriendApplications`,
    JSON.stringify(list)
  );
export const setAccessedGroupApplication = (list: string[]) =>
  localStorage.setItem(
    `${getIMUserID()}_accessedGroupApplications`,
    JSON.stringify(list)
  );

export const setIMProfile = ({ chatToken, imToken, userID, chatType, adminToken }: any) => {
  setTMToken(imToken);
  setChatToken(chatToken);
  setTMUserID(userID);
  setChatType(chatType);
  setAdminToken(adminToken);
};

export const clearIMProfile = () => {
  localStorage.removeItem("IM_TOKEN");
  localStorage.removeItem("IM_CHAT_TOKEN");
  localStorage.removeItem("IM_USERID");
  localStorage.removeItem("IM_ChatType");
  localStorage.removeItem("IM_ADMIN_TOKEN");
};

export const getIMToken = () => localStorage.getItem("IM_TOKEN");
export const getChatToken = () => localStorage.getItem("IM_CHAT_TOKEN");
export const getIMUserID = () => localStorage.getItem("IM_USERID");
export const getIMChatType = () => localStorage.getItem("IM_ChatType");
export const getAdminToken = () => localStorage.getItem("IM_ADMIN_TOKEN");

export const getAccessedFriendApplication = () =>
  localStorage.getItem(`${getIMUserID()}_accessedFriendApplications`)
    ? JSON.parse(
      localStorage.getItem(`${getIMUserID()}_accessedFriendApplications`)!
    )
    : [];
export const getAccessedGroupApplication = () =>
  localStorage.getItem(`${getIMUserID()}_accessedGroupApplications`)
    ? JSON.parse(
      localStorage.getItem(`${getIMUserID()}_accessedGroupApplications`)!
    )
    : [];
